//
//  RefundDetailsVc.swift
//  Pods
//
//  Created by eme on 2017/4/25.
//
//

import UIKit
import UtilCore

class RefundDetailsVc: Base_Vc {
    
    /****************************Storyboard UI设置区域****************************/
    
    @IBOutlet weak var custom_TableView: UITableView!           //
    
    @IBOutlet weak var price_Label: UILabel!                    //价格Label
    
    @IBOutlet weak var time_Label: UILabel!                     //时间Label
    
    /*----------------------------   自定义属性区域    ----------------------------*/
    var getRefundVM:GetRefundVM?
    var refundModel:RefundModel?
    var deteilID:String?
    var isHidden = false
    
    /****************************Storyboard 绑定方法区域****************************/
    
    
    
    /**************************** 以下是方法区域 ****************************/
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.getRefundVM?.request.onNext(deteilID ?? "")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    /**
     界面基础设置
     */
    override func setupUI() {
        /**
         *  自定义 导航栏左侧 返回按钮
         */
        self.customLeftBarButtonItem()
        self.setUpTableView()
    }
    func setUpTableView(){
        self.custom_TableView.delegate = self
        self.custom_TableView.dataSource = self
        self.custom_TableView.estimatedRowHeight = 100
        self.custom_TableView.rowHeight = UITableViewAutomaticDimension
    }
    func callPhone(){
        
        
        UIApplication.shared.openURL(NSURL(string :"tel://"+"\(self.refundModel?.phone ?? "")")! as URL)
        
//        let aleatView = UIAlertController(title:self.refundModel?.phone ?? "" , message: "", preferredStyle:.alert)
//        let archiveAction = UIAlertAction.init(title: "拨打", style: .default, handler: { _ in
//            
//            
//            
//        })
//        let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel, handler: nil)
//        aleatView.addAction(cancelAction)
//        aleatView.addAction(archiveAction)
//        self.present(aleatView, animated: true, completion: nil)
    }
    /**
     绑定到viewmodel 设置
     */
    override func bindToViewModel(){
        
        self.getRefundVM = GetRefundVM()
        self.getRefundVM?.backDate.subscribe(onNext:{ data in
            
            self.refundModel = data
            self.custom_TableView.reloadData()
            self.price_Label.text = data.amount.getPriceStr()
            self.time_Label.text = data.odate
            
            }).addDisposableTo(disposeBag)
        
        self.getRefundVM?.error.bindTo(self.view.rx_error).addDisposableTo(disposeBag)
        
    }
}
extension RefundDetailsVc:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TKXQ_TableViewCell
        cell.item = self.refundModel
        cell.CallPhone.addTarget(self, action: #selector(RefundDetailsVc.callPhone), for: .touchUpInside)
        cell.CallPhone.isHidden = isHidden
        return cell
    }
}
